// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   SignAction.java

package com.vandagroup.security;

import com.vandagroup.common.bo.UserContext;
import com.vandagroup.common.webapp.ActiveAction;
import com.vandagroup.common.webapp.ResourceReader;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.*;

// Referenced classes of package com.vandagroup.security:
//            SignBO, SignFormBean

public class SignAction extends ActiveAction
{

    public SignAction()
    {
    }

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, UserContext user)
        throws Exception
    {
        if(task == null || task.equals(""))
            return forwardErrorPage(request, mapping, ResourceReader.getMessageFromResource("error.paralose"));
        if(step == null || step.equals(""))
            return forwardErrorPage(request, mapping, ResourceReader.getMessageFromResource("error.paralose"));
        try
        {
            if(task.equals("list"))
                return doList(mapping, form, request, response, user);
            if(task.equals("new"))
                return doAdd(mapping, form, request, response, user);
            if(task.equals("edit"))
                return doEdit(mapping, form, request, response, user);
            if(task.equals("view"))
                return doView(mapping, form, request, response, user);
            if(task.equals("delete"))
                return doDelete(mapping, form, request, response, user);
            else
                return forwardErrorPage(request, mapping, ResourceReader.getMessageFromResource("error.paralose"));
        }
        catch(Exception e)
        {
            e.printStackTrace();
            return forwardErrorPage(request, mapping, ResourceReader.getMessageFromResource("error.security"), e);
        }
    }

    public ActionForward doAdd(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, UserContext user)
        throws Exception
    {
        if(step.equals("init"))
            return mapping.findForward("add");
        if(step.equals("submit"))
            try
            {
                SignBO bo = new SignBO();
                int rtn = bo.add((SignFormBean)form);
                return new ActionForward("/Sign.do?task=list&step=list");
            }
            catch(Exception e)
            {
                e.printStackTrace();
                return forwardErrorPage(request, mapping, ResourceReader.getMessageFromResource("error.security.add"), e);
            }
        else
            return null;
    }

    public ActionForward doView(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, UserContext user)
        throws Exception
    {
        try
        {
            SignFormBean bean = (SignFormBean)form;
            SignBO bo = new SignBO();
            request.setAttribute("form", bo.retrieveForm(bean));
            return mapping.findForward("view");
        }
        catch(Exception e)
        {
            e.printStackTrace();
            return forwardErrorPage(request, mapping, ResourceReader.getMessageFromResource("error.security.view"), e);
        }
    }

    public ActionForward doEdit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, UserContext user)
        throws Exception
    {
        if(step.equals("init"))
            try
            {
                SignFormBean bean = (SignFormBean)form;
                SignBO bo = new SignBO();
                request.setAttribute("form", bo.retrieveForm(bean));
                return mapping.findForward("edit");
            }
            catch(Exception e)
            {
                e.printStackTrace();
                return forwardErrorPage(request, mapping, ResourceReader.getMessageFromResource("error.security.view"), e);
            }
        if(step.equals("submit"))
            try
            {
                SignBO bo = new SignBO();
                bo.update((SignFormBean)form);
                return new ActionForward("/Sign.do?task=list&step=list");
            }
            catch(Exception e)
            {
                e.printStackTrace();
                return forwardErrorPage(request, mapping, ResourceReader.getMessageFromResource("error.security.modi"), e);
            }
        else
            return null;
    }

    public ActionForward doList(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, UserContext user)
        throws Exception
    {
        if(step.equals("list"))
        {
            String strPageNO = request.getParameter("pageNO");
            int pageNO = strPageNO == null ? Integer.parseInt("1") : Integer.parseInt(strPageNO);
            try
            {
                SignBO bo = new SignBO();
                SignFormBean bean = (SignFormBean)form;
                com.vandagroup.common.util.Result t = bo.query(pageNO, bean);
                request.setAttribute("result", t);
                request.setAttribute("form", bean);
                return mapping.findForward("list");
            }
            catch(Exception e)
            {
                e.printStackTrace();
                return forwardErrorPage(request, mapping, ResourceReader.getMessageFromResource("error.security.search"), e);
            }
        } else
        {
            return forwardErrorPage(request, mapping, ResourceReader.getMessageFromResource("error.steplose"));
        }
    }

    public ActionForward doDelete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, UserContext user)
        throws Exception
    {
        try
        {
            SignFormBean bean = (SignFormBean)form;
            SignBO bo = new SignBO();
            int rtn = bo.remove(request.getParameterValues("selOperID"));
            return new ActionForward("/Sign.do?task=list&step=list");
        }
        catch(Exception e)
        {
            e.printStackTrace();
            return forwardErrorPage(request, mapping, ResourceReader.getMessageFromResource("error.security.del"), e);
        }
    }
}
